import csv
from matplotlib import pyplot as plt
from datetime import datetime


finename_year = '../file/sitka_weather_2014.csv'
with open(finename_year) as file:
    reader = csv.reader(file)
    header_row = next(reader)

    for index,column_header in enumerate(header_row):
        print(index,column_header)


    # 从文件中读取每天的日期和最高气温，并存放到一个列表中
    dates,highs,lows = [],[],[]

    for row in reader:
        high = int(row[1])
        highs.append(high)

        low = int(row[3])
        lows.append(low)

        current_date = datetime.strptime(row[0],'%Y-%m-%d')
        dates.append(current_date)

    print(highs)

    # 根据数据绘制图形
    fig = plt.figure(dpi=128,figsize=(10,6))
    plt.plot(dates,highs,c='red',alpha=0.5)
    plt.plot(dates,lows,c='blue',alpha=0.5)

    # 给图标区域着色，接受一个x值系列，和两个y值系列，填充俩个y值系列之间的空间
    plt.fill_between(dates,highs,lows,facecolor='blue',alpha=0.1)

    # 设置图形的格式
    plt.title("Minimum temperature and minimum temperature in 2014",fontsize=14)
    plt.xlabel("",fontsize=16)

    fig.autofmt_xdate()

    plt.ylabel("Temperature(F)",fontsize=16)
    plt.tick_params(axis='both',which='major',labelsize=16)

    plt.show()